Hide buffer right before command execution
authorBar Magal <barmagal@gmail.com>
Mon, 6 Jul 2015 16:34:31 +0000 (19:34 +0300)
committerBar Magal <barmagal@gmail.com>
Mon, 6 Jul 2015 16:34:31 +0000 (19:34 +0300)
Fixes #9, this is also what guide-key uses.

When quoting functions, using "#'" tells the compiler that you're
quoting a function, and allows it to catch void function errors.

which-key.el

index 7c7e16753ba85da52b39be32d197a30bf1ec3954..4f1e8c2344005b450923b75b03617bcac508f974 100644 (file)
@@ -81,17 +81,19 @@ Used when `which-key-popup-type' is frame.")
       (progn
         (unless which-key--setup-p (which-key/setup))
         ;; make echo-keytrokes fast for minibuffer popup
-       ;; (it can interfer if it's too slow)
+        ;; (it can interfer if it's too slow)
         (when (and (> echo-keystrokes 0)
-                  (eq which-key-popup-type 'minibuffer))
-         (setq echo-keystrokes 0.1))
-        (add-hook 'focus-out-hook 'which-key/stop-open-timer)
-        (add-hook 'focus-in-hook 'which-key/start-open-timer)
+                   (eq which-key-popup-type 'minibuffer))
+          (setq echo-keystrokes 0.1))
+        (add-hook 'pre-command-hook #'which-key/hide-popup)
+        (add-hook 'focus-out-hook #'which-key/stop-open-timer)
+        (add-hook 'focus-in-hook #'which-key/start-open-timer)
         (which-key/start-open-timer))
     ;; make sure echo-keystrokes returns to original value
     (setq echo-keystrokes which-key--echo-keystrokes-backup)
-    (remove-hook 'focus-out-hook 'which-key/stop-open-timer)
-    (remove-hook 'focus-in-hook 'which-key/start-open-timer)
+    (remove-hook 'pre-command-hook #'which-key/hide-popup)
+    (remove-hook 'focus-out-hook #'which-key/stop-open-timer)
+    (remove-hook 'focus-in-hook #'which-key/start-open-timer)
     (which-key/stop-open-timer)
     (which-key/stop-close-timer)))